
//PLALISTS.JS
//shows a list of playlists in library
// Author: Wilco

function playlistsPage() {}
playlistsPage.prototype.constructor = playlistsPage;
playlistsPage.prototype =
{
    templateData: '',
    playlistsData: {},
    loadPage: function()
    {
        this.onOutput = function(title,pageTemplate) { ProcessPageOutput(title,pageTemplate,'',true); }
        this.loadDefaults();
        //Load template data
        LoadFile(SkinDir + 'playlists.html', this.onLoadTemplate.bind(this));
    },
    loadDefaults: function()
    {  
       //No Defaults
    },
    onLoadTemplate: function(response)
    {
        this.templateData = response;
        this.loadData();
    },
    loadData: function()
    {
        //Load playlists data
        var url = ServiceDir + 'playlists'; 
        LoadFile(url, this.onLoadData.bind(this));
    },
    onLoadData: function(response)
    {
       this.playlistsData = response;
       this.generateOutput();
    },
    generateOutput: function()
    {
		
        try
        {    var playlistsData = eval("(" + this.playlistsData + ")"); }
        catch (e)
        {    showError('Cannot understand service data'); return; }        

		var tmplData = { item: [] };
		for(var i=0;i<playlistsData.length;i++)
		{
			tmplData.item.push({ name: playlistsData[i].name, guid: playlistsData[i].guid });
		}
		
		var tmpl = new Template();
		tmpl.load(this.templateData);
		tmpl.setData(tmplData);
		
        this.onOutput('Playlists',tmpl);
    },
    onOutput: function(){},
}


gLastScriptLoaded = new playlistsPage();
gScriptLoaded();